﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FlickrWP7.Core
{
    public class Activity
    {
        private  HelperDelegate helperDelegateInstance;

        public  string LastActivityResult { get; set; }

        public  void GetUserPhotos(string apiKey, string signature, string authToken, HelperDelegate helperDelegate, string page = "", string timeframe = "", string resultsPerPage = "" )
        {
            helperDelegateInstance = helperDelegate;

            WebClient client = new WebClient();
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            string URL = string.Format("http://www.flickr.com/services/rest/?method=flickr.activity.userPhotos&api_key={0}&api_sig={1}&auth_token={2}&format=json",
                    apiKey, signature,authToken);

            if (page != "")
                URL += "&page=" + page;
            if (timeframe != "")
                URL += "&timeframe=" + timeframe;
            if (resultsPerPage != "")
                URL += "&per_page=" + resultsPerPage;

            client.DownloadStringAsync(new Uri(URL));
        }

        public void GetUserComments(string apiKey, string signature, string authToken, HelperDelegate helperDelegate, string page = "", string resultsPerPage = "")
        {
            helperDelegateInstance = helperDelegate;

            WebClient client = new WebClient();
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            string URL = string.Format("http://www.flickr.com/services/rest/?method=flickr.activity.userComments&api_key={0}&api_sig={1}&auth_token={2}&format=json",
                    apiKey, signature, authToken);

            if (page != "")
                URL += "&page=" + page;
            if (resultsPerPage != "")
                URL += "&per_page=" + resultsPerPage;

            client.DownloadStringAsync(new Uri(URL));
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            LastActivityResult = e.Result;
            helperDelegateInstance();
        }
    }
}
